package com.rd.student.jiaji.class3.sunguowei.day31;

import java.util.ArrayList;
import java.util.HashSet;

public class TestRandom3 {
    public static void main(String[] args) {
//       test1();
        test2();
    }

    public static void test1() {
        HashSet set = new HashSet<>();
        while (set.size() < 20) {
            int random = (int) (Math.random() * 50);
            set.add(random);
        }
        System.out.println(set);
    }

    public static void test2() {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            int random = (int) (Math.random() * 50);
            if (list.contains(random)) {
                i--;
                continue;
            }
            list.add(random);
        }
        System.out.println(list);
    }
    public static void test3(){
        ArrayList<Integer> list = new ArrayList<>();
        while (list.size()<20) {
            int random = (int) (Math.random() * 50);
            if (!list.contains(random)) {
                list.add(random);
            }
        }
        System.out.println(list);

    }
}